﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernateClass
{
    public class SessionFactory
    {
        private static NHibernate.ISessionFactory _Sessionfactory;

        private static void Init()
        {
            NHibernate.Cfg.Configuration config;
            config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.AddAssembly("NHibernateClass");
            _Sessionfactory = config.BuildSessionFactory();
        }

        public static NHibernate.ISessionFactory GetSessionFactory()
        {
            if (_Sessionfactory == null)
            {
                Init();
            }
            return _Sessionfactory;
        }

        public static NHibernate.ISession GetNewSession()
        {
            return GetSessionFactory().OpenSession();
        }
    }
}
